package ar.com.spsolutions.splilabrary.view.pages.book;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;

import ar.com.spsolutions.splibrary.book.BookComment;

public class BookCommentPanelContainer extends Panel {
    private static final long serialVersionUID = -3085027113840826860L;

    private List<BookComment> comments;

    public BookCommentPanelContainer(final String id, final List<BookComment> comments) {
        super(id);
        this.comments = comments;
        addList();
        // addNewComment();
    }

    public BookCommentPanelContainer(final String id) {
        this(id, new ArrayList<BookComment>());
    }

    private void addList() {
        final ListView<BookComment> list = new ListView<BookComment>("bookComment", getComments()) {

            private static final long serialVersionUID = 3634224977916608964L;

            @Override
            protected void populateItem(final ListItem<BookComment> item) {
                final BookCommentPanel bookCommentPanel = new BookCommentPanel("bookCommentPanel",
                        item.getModelObject());
                item.add(bookCommentPanel);
            }
        };
        this.add(list);
    }

    public List<BookComment> getComments() {
        if (comments == null) {
            return new ArrayList<BookComment>();
        }
        return comments;
    }

    public void setComments(final List<BookComment> comments) {
        this.comments = comments;
    }

}
